<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Restful Example--User Management</title>

<jsp:include page="../header.jsp"><jsp:param name="groups" value="jquery,jquery-ui,common"/></jsp:include>

<script type="text/javascript">
$(document).ready(function(){

	var getVersionURL = 'PartyModuleAction/getVersion.do';
	var applyVersionURL = 'PartyModuleAction/applyVersion.do';
	

	$.ajax({
		url: getVersionURL,
		dataType: 'text',
		success: function(result){
			$('#moduleListTable input[name=partyVersion]').each(function() {
				if($(this).val() == result) {
					$(this).attr('checked', 'checked');
					$(this).parent().parent().addClass('ui-state-highlight');
				}
				else {
					$(this).attr('checked', null);
					$(this).parent().parent().removeClass('ui-state-highlight');
				}
			});
		}
	});


	
	$('#onApplyVersion').click(function(){
		var partyVersion;
		$('#moduleListTable input[name=partyVersion]').each(function() {
			if($(this).attr('checked') != null) {
				partyVersion = $(this).val();
			}
		});
		
		$.ajax({
			type: 'GET',
			url: applyVersionURL + '?partyVersion=' + partyVersion,
			success: function(result){
				if(result != null && result.level == 'INFO') {
					//Added the highlight class style
					$('#moduleListTable input[name=partyVersion]').each(function() {
						if($(this).attr('checked') != null) {
							$(this).parent().parent().addClass('ui-state-highlight');
						}
						else {
							$(this).parent().parent().removeClass('ui-state-highlight');
						}
					});
					
					$.msgBox('info', 'Information', result.message);
				}
				else {
					$.msgBox('warn', 'Waring', result.message);
				}
			}
		});
		
		return false;
	});

	

	$('button').button();
});

</script>

</head>
<body>
<center>
<div class="contentArea">
	<div  style="text-align:left">
		<h1>Party Module Switcher</h1>
		<div>-- Show how to switch the module classes at runtime.<div>
	</div>
	<br/>
	<table id="moduleListTable" class="ui-widget ui-widget-content" width="100%">
		<thead>
			<tr class="ui-widget-header ">
				<th>&nbsp;</th>
				<th>Description</th>
				<th>ClassPaths</th>
			</tr>
		</thead>
		<tbody id="moduleListTbody">
			<tr>
				<td><input type="radio" name="partyVersion" value="1"/></td>
				<td>Version 1 - Basic user info, including fields: username, name, email.</td>
				<td>eshop-party/classes-v1/</td>
			</tr>
			<tr>
				<td><input type="radio" name="partyVersion" value="2"/></td>
				<td>Version 2 - Extension user info, including more fields: username, name, email, birthday, phone, mobile.</td>
				<td>eshop-party/classes-v2/</td>
			</tr>
		</tbody>
		<tfood>
			<tr><td colspan="3" align="left">
			&nbsp;&nbsp;&nbsp;&nbsp;<button id="onApplyVersion">Apply</button>
			</td></tr>
		</tfood>
	</table>
	<div  style="text-align:left">
		<h3>
		To view the changes, please inside the menu <a href="../party/user.jsp" style="font-color:red;">"User"</a>.
		</h3>
	</div>
</div>
</center>
</body>
</html>

	